package com.yanfan.ccapi.controller;

import com.yanfan.ccapi.service.ICcapiProductTypeMappingService;
import com.yanfan.ccapicode.dao.entity.ProductTypeMappingDO;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.core.page.TableDataInfo;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 产品类型映射关系Controller
 *
 * @author kerwincui
 * @date 2025-06-29
 */
@RestController
@RequestMapping("/ccapi/productTypeMapping")
@Api(tags = "产品类型映射关系")
public class CcapiProductTypeMappingController extends BaseController {
    @Autowired
    private ICcapiProductTypeMappingService ccapiProductTypeMappingService;

    /**
     * 查询产品类型映射关系列表
     */
//@PreAuthorize("@ss.hasPermi('ccapi:productTypeMapping:list')")
    @GetMapping("/list")
    @ApiOperation("查询产品类型映射关系列表")
    public TableDataInfo list(ProductTypeMappingDO ccapiProductTypeMapping) {
        startPage();
        List<ProductTypeMappingDO> list = ccapiProductTypeMappingService.selectCcapiProductTypeMappingList(ccapiProductTypeMapping);
        return getDataTable(list);
    }

    /**
     * 导出产品类型映射关系列表
     */
    @ApiOperation("导出产品类型映射关系列表")
    //@PreAuthorize("@ss.hasPermi('ccapi:productTypeMapping:export')")
    @Log(title = "产品类型映射关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductTypeMappingDO ccapiProductTypeMapping) {
        List<ProductTypeMappingDO> list = ccapiProductTypeMappingService.selectCcapiProductTypeMappingList(ccapiProductTypeMapping);
        ExcelUtil<ProductTypeMappingDO> util = new ExcelUtil<ProductTypeMappingDO>(ProductTypeMappingDO.class);
        util.exportExcel(response, list, "产品类型映射关系数据");
    }

    /**
     * 获取产品类型映射关系详细信息
     */
    //@PreAuthorize("@ss.hasPermi('ccapi:productTypeMapping:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取产品类型映射关系详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ccapiProductTypeMappingService.selectCcapiProductTypeMappingById(id));
    }

    /**
     * 新增产品类型映射关系
     */
    //@PreAuthorize("@ss.hasPermi('ccapi:productTypeMapping:add')")
    @Log(title = "产品类型映射关系", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增产品类型映射关系")
    public AjaxResult add(@RequestBody ProductTypeMappingDO ccapiProductTypeMapping) {
        return toAjax(ccapiProductTypeMappingService.insertCcapiProductTypeMapping(ccapiProductTypeMapping));
    }

    /**
     * 修改产品类型映射关系
     */
    //@PreAuthorize("@ss.hasPermi('ccapi:productTypeMapping:edit')")
    @Log(title = "产品类型映射关系", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改产品类型映射关系")
    public AjaxResult edit(@RequestBody ProductTypeMappingDO ccapiProductTypeMapping) {
        return toAjax(ccapiProductTypeMappingService.updateCcapiProductTypeMapping(ccapiProductTypeMapping));
    }

    /**
     * 删除产品类型映射关系
     */
    //@PreAuthorize("@ss.hasPermi('ccapi:productTypeMapping:remove')")
    @Log(title = "产品类型映射关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除产品类型映射关系")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ccapiProductTypeMappingService.deleteCcapiProductTypeMappingByIds(ids));
    }
}
